define([
	'jquery',
	'underscore',
	'backbone',
	'services/entryService'
], function($, _, Backbone, EntryService){
	
	function changeBodyEvent(model) {
		var body = model.get('body');
		console.log('body zmienione!');
		body = body.replace('@', '#@');
		model.set('body', body, {silent: true});
	}
	
	var EntryModel = Backbone.Model.extend({
		initialize: function(id) {
			if($.isNumeric(id)) {
				console.log(EntryService.get(id, this));
				this.set(EntryService.get(id, this));
				
//				changeBodyEvent(this);
				this.trigger('change:body');
				
				console.log(this);
			}
			
			this.on({
				'change:body': function(){ changeBodyEvent(this); }
			});
		}
	});
	
	return EntryModel;
});